import Flutter
import UIKit

public class FlupluginPlugin: NSObject, FlutterPlugin , FlutterStreamHandler{
  
    var methodChannel : FlutterMethodChannel?
        var eventChannel : FlutterEventChannel?
        public static var eventSink : FlutterEventSink?
        
    public static func register(with registrar: FlutterPluginRegistrar) {
        FlupluginPlugin.init(registrar: registrar)
            registrar.register(FluFactory.init(binaryMessenger: registrar.messenger()), withId: "com.lx.fluview")
        }
        
        override init() {
            super.init()
        }
        
        convenience init(registrar: FlutterPluginRegistrar) {
            self.init()
            methodChannel = FlutterMethodChannel.init(name: "com.lx.methodChannel", binaryMessenger: registrar.messenger())
            methodChannel?.setMethodCallHandler(handle)
            eventChannel = FlutterEventChannel.init(name: "com.lx.eventChannel", binaryMessenger: registrar.messenger())
            eventChannel?.setStreamHandler(self)
        }
        
        public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
           let method =  call.method
            let argumentsTemp = call.arguments
            print("all--->method=\(method),arguments=\(argumentsTemp)")
            if(method == "addNum"){
                if(argumentsTemp != nil){
                    let arguments = argumentsTemp as! Dictionary<String,Any?>
                    let num = arguments["num"] as? Int
                    
                }
            }
        }
        
    public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
            FlupluginPlugin.eventSink = events
            return nil
        }
        
    public func onCancel(withArguments arguments: Any?) -> FlutterError? {
            FlupluginPlugin.eventSink = nil
            return nil
        }
}
